﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.IO;

namespace DSA
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }
        public void alert(string msg)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("alert('");
            sb.Append(msg.Replace("\n", "\\n").Replace("\r", "").Replace("'", "\\'"));
            sb.Append("');");
            ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "showalert", sb.ToString(), true);
        }

        static Key readKey(string priv, string pub)
        {
            Key key = new Key();

            using (var reader = new StreamReader(pub))
            {
                key.P = new BigInteger(reader.ReadLine(), 10);
                key.Q = new BigInteger(reader.ReadLine(), 10);
                key.G = new BigInteger(reader.ReadLine(), 10);
                key.Y = new BigInteger(reader.ReadLine(), 10);
            }
            using (var reader = new StreamReader(priv))
            {
                key.X = new BigInteger(reader.ReadLine(), 10);
            }
            return key;
        }

        protected void Button_Generate_Click(object sender, EventArgs e)
        {
            var key = DigitalSignatureStandard.GenerateKey();
            using (var writer = new StreamWriter("public"))
            {
                writer.WriteLine(key.P); labelP.Text = "P = " + key.P.ToString();
                writer.WriteLine(key.Q); labelQ.Text = "Q = " + key.Q.ToString();
                writer.WriteLine(key.G); labelG.Text = "G = " + key.G.ToString();
                writer.WriteLine(key.Y); labelY.Text = "Y = " + key.Y.ToString();
            }
            using (var writer = new StreamWriter("private"))
            {
                writer.WriteLine(key.X); labelX.Text = "X = " + key.X.ToString();
            }
        }
    }
}
